//用户模块api请求
import request from '@/utils/request'
import type {ResponseData} from '@/api/types/type.ts'
import {
    CreateUserData,
    RequestData,
    ResponseLoginData,
    ResponseUserInfo,
    UpdateUserData, UpdateUserPInfoData,
    UserListData, UserPInfoResponse
} from "./types.ts";

// 获取用户信息
export function getUserInfo(): Promise<ResponseUserInfo> {
    return request({
        url: "/public/user/info",
        method: 'get',
    })
}

// 修改用户信息
export function updateUserInfo(data: UpdateUserData): Promise<ResponseData> {
    return request({
        url: '/user/updateUser',
        method: 'post',
        data,
    })
}

// 修改用户密码
export function updateUserPassword(data: any): Promise<ResponseData> {
    return request({
        url: '/user/password',
        method: 'post',
        data,
    })
}

// 获取用户按钮
export function getUserButton(): Promise<ResponseData> {
    return request({
        url: '/user/button',
        method: 'get',
    })
}

// 获取用户列表
export function getUserList(data: RequestData): Promise<UserListData> {
    return request({
        url: '/user/getUserList',
        method: 'post',
        data,
    })
}

// 添加用户
export function createUser(data: CreateUserData): Promise<ResponseData> {
    return request({
        url: '/user/createUser',
        method: 'post',
        data,
    })
}

// 删除用户
export function deleteUser(id: any): Promise<ResponseData> {
    return request({
        url: '/user/deleteUser?id=' + id,
        method: 'DELETE',
    })
}

// 批量删除用户
export function deleteUsers(ids: number[]): Promise<ResponseData> {
    return request({
        url: '/user/deleteUsers',
        method: 'DELETE',
        data: {"ids": ids}
    })
}

// 账号登录
export function login(data: any): Promise<ResponseLoginData> {
    return request({
        url: '/public/user/login',
        method: 'post',
        data,
    })
}

// 账号退出
export function logout(): Promise<ResponseData> {
    return request({
        url: '/public/user/logout',
        method: 'post',
    })
}

//获取用户个人中心数据
export function getUserCenterInfo(): Promise<UserPInfoResponse> {
    return request({
        url: '/public/user/center',
        method: 'get',
    })
}

// 获取头像
export function getAvatar(avatarName: string): Promise<any> {
    return request({
        url: '/public/user/avatar/' + avatarName,
        method: 'get',
        responseType: 'blob',
    })
}

// 更新头像
export function updateAvatar(avatar: string): Promise<ResponseData> {
    return request({
        url: '/public/user/updateAvatar/' + avatar,
        method: 'get',
    })
}

// 个人中心数据修改
export function updateUserCenterInfo(data: UpdateUserPInfoData): Promise<ResponseData> {
    return request({
        url: '/public/user/updateInfo',
        method: 'post',
        data,
    })
}
